package com.jingdianjichi.domain.service.impl;

import com.jingdianjichi.auth.infra.basic.entity.AuthRolePermission;
import com.jingdianjichi.auth.infra.basic.service.AuthRolePermissionService;
import com.jingdianjichi.domain.entity.AuthRolePermissionBO;
import com.jingdianjichi.domain.service.AuthRolePermissionDomainService;
import com.jingdianjichi.enums.IsDeletedFlagEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {


    @Resource
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public Boolean add(AuthRolePermissionBO rolePermissionBO) {
        ArrayList<AuthRolePermission> authRolePermissions = new ArrayList<>();
        Long roleId = rolePermissionBO.getRoleId();
        rolePermissionBO.getPermissionIdList().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            authRolePermissions.add(authRolePermission);
        });
        Integer count = authRolePermissionService.InsertBatch(authRolePermissions);
        return count > 0;
    }
}
